package com.cp.monitor;

import com.cp.properties.CpMetricsProperties;
import io.micrometer.core.instrument.MeterRegistry;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * Des:
 *
 * @author cp
 * @date 2022/8/28 13:23
 */
@Slf4j
@Configuration
@Import(CpMetricsProperties.class)
public class MonitorAutoConfiguration {

    @Bean
    @ConditionalOnProperty(prefix = "monitor", name = "isOpen", havingValue = "true")
    MeterRegistryCustomizer<MeterRegistry> configurer(
            @Value("${spring.application.name}") String applicationName) {
        log.info("cp-framework prometheus监控启用");
        return (registry) -> registry.config().commonTags("application", applicationName);
    }

}
